<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let userInfo = {
            username:"文渊",
            age:98,
            gender:"男",
            address:{
                addressInfo1:"江西",
                addressInfo2:"深圳"
            },
            hobby:["唱","跳","rap","篮球","miusic"]
        }
        let studentInfo = {}


        //深拷贝 => 递归
        function deepCopy(newData,oldData){
            //我们需要考虑复杂数据类型有 对象 + 数组
            for(let key in oldData){
                //如果对象
                if(Object.prototype.toString.call(oldData[key]) === '[object Object]'){
                    //要在新数据当中创建一个名字一样的对象
                    newData[key] = {}
                    //递归,传递老数据和新数组
                    deepCopy(newData[key],oldData[key])
                //如果是数组
                }else if(Object.prototype.toString.call(oldData[key]) === '[object Array]'){
                    //要在新数组当中创建一个名字一样的数组
                    newData[key] = []
                    deepCopy(newData[key],oldData[key])
                }else{
                //基本数据类型
                     newData[key] = oldData[key]
                }
            } 
        }
        deepCopy(studentInfo,userInfo)

        userInfo.username = "文天祥"
        userInfo.address.addressInfo1 = "武汉"

        console.log(studentInfo,userInfo);
    </script>
</body>
</html>